#!/bin/bash

dir0="$PWD"
mkdir -p "${dir0}/diffs"

spec="$(ls *.spec | head -n 1)"
echo "$spec"

if grep -qi "^buildarch:" "$spec"
	then
		grep_pattern="^buildarch:"
		h=tail
		s="++"
	else
		grep_pattern="^buildrequires:"
		h=head
		s="--"
fi

n="$(grep -ni $grep_pattern "$spec" | awk -F ':' '{print $1}' | "$h" -n 1)"
n=$((${s}n))

sed -i "${n} i # Java stack is not supported on x86_32" "$spec"
n=$((++n))
sed -i "${n} i ExcludeArch: %{ix86}" "$spec"

# check manually, grep -inHrEl '%endif|%else|%if'
# avoid ExcludeArch under if-else

git add *.spec
git commit -m 'Drop Java stack on x86_32'
git push

